<template>
    <!-- 对话框表单 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :destroy-on-close="true"
        :model-value="['Add', 'Edit'].includes(baTable.form.operate!)"
        @close="baTable.toggleForm"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    ref="formRef"
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    label-position="right"
                    :label-width="baTable.form.labelWidth + 'px'"
                    v-if="!baTable.form.loading"
                >
                    <el-form-item prop="username" :label="t('user.user.User name')">
                        <el-input v-model="baTable.form.items!.username" type="string" :disabled="baTable.form.operate == 'Add' ? false : true"></el-input>
                    </el-form-item>

                    <el-form-item prop="password" :label="t('user.user.password')">
                        <el-input
                            v-model="baTable.form.items!.password"

                            type="string"
                            :placeholder="baTable.form.operate == 'Add' ? '' : t('user.user.Please leave blank if not modified')"
                        ></el-input>
                    </el-form-item> 

                    <el-form-item prop="email" :label="t('user.user.email')">
                        <el-input v-model="baTable.form.items!.email" type="string"></el-input>
                    </el-form-item>
                    
                    <el-form-item prop="big" :label="t('user.user.big') + ' / ' + t('universal.kilogram')">
                        <el-input v-model="baTable.form.items!.big" type="number"></el-input>
                    </el-form-item>
                    <el-form-item prop="small" :label="t('user.user.small') + ' / ' + t('universal.kilogram')">
                        <el-input v-model="baTable.form.items!.small" type="number"></el-input>
                    </el-form-item>
                    <el-form-item prop="contact" :label="t('user.user.contact')">
                        <el-input v-model="baTable.form.items!.contact" type="string"></el-input>
                    </el-form-item>
                    <el-form-item prop="wechat" :label="t('user.user.wechat')">
                        <el-input v-model="baTable.form.items!.wechat" type="string"></el-input>
                    </el-form-item>
                    <el-form-item prop="contact_designated_logistics" :label="t('user.user.contact') + '(' + t('user.user.Designated logistics') + ')'">
                        <el-input v-model="baTable.form.items!.contact_designated_logistics" type="string"></el-input>
                    </el-form-item>
                    <el-form-item prop="designated_logistics" :label="t('user.user.Designated logistics')">
                        <el-input v-model="baTable.form.items!.designated_logistics" type="string"></el-input>
                    </el-form-item>
                    <el-form-item prop="note" :label="t('user.user.note')">
                        <el-input
                            @keyup.enter.stop=""
                            @keyup.ctrl.enter="baTable.onSubmit(formRef)"
                            v-model="baTable.form.items!.note"
                            type="textarea"
                        ></el-input>
                    </el-form-item>
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm('')">{{ t('Cancel') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive, inject, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import { regularPassword } from '/@/utils/validate'
import type { FormInstance, FormItemRule } from 'element-plus'
import FormItem from '/@/components/formItem/index.vue'
import router from '/@/router/index'
import { buildValidatorData } from '/@/utils/validate'

const formRef = ref<FormInstance>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()


</script>

<style scoped lang="scss">
.avatar-uploader {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-radius: var(--el-border-radius-small);
    box-shadow: var(--el-box-shadow-light);
    border: 1px dashed var(--el-border-color);
    cursor: pointer;
    overflow: hidden;
    width: 110px;
    height: 110px;
}
.avatar-uploader:hover {
    border-color: var(--el-color-primary);
}
.avatar {
    width: 110px;
    height: 110px;
    display: block;
}
.image-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}
</style>
